#include "qprojectwidget.h"

#include "qprojectpropertyview.h"
#include "qusermanagerview.h"
#include "qlanguagemanagerview.h"

#include "../../libs/corelib/minisplitter.h"
#include "../../libs/coreLib/qsoftcore.h"
#include "../../libs/sharedLib/qcommonstruct.h"


#include <QVBoxLayout>

QProjectWidget::QProjectWidget():
    CORELIB::QAbstractPageWidget(0),
    m_splitter(new CORELIB::MiniSplitter(Qt::Horizontal)),
    m_propertyView(new QProjectPropertyView),
    m_userManager(new QUserManagerView),
    m_languageManager(new QLanguageManagerView)
{
    QVBoxLayout *l=new QVBoxLayout;
    l->setMargin(0);
    l->setSpacing(0);

    this->setLayout(l);

    l->addWidget(m_splitter);

    m_splitter->addWidget(m_propertyView);

    CORELIB::MiniSplitter   *splitter=new CORELIB::MiniSplitter(Qt::Vertical);
    splitter->addWidget(m_userManager);
    splitter->addWidget(m_languageManager);

    m_splitter->addWidget(splitter);


    m_splitter->setStretchFactor(0,0);
    m_splitter->setStretchFactor(1,1);

    connect(m_propertyView,SIGNAL(need_make_page_position()),this,SLOT(make_page_position()));
    connect(m_languageManager,SIGNAL(need_make_page_position()),this,SLOT(make_page_position()));
    connect(m_userManager,SIGNAL(need_make_page_position()),this,SLOT(make_page_position()));
}

bool QProjectWidget::pagePosition(const QVariant &param)
{
    bool ret=false;
    if(m_propertyView->pagePosition(param))
    {
        ret=true;
    }

    if(m_languageManager->pagePosition(param))
    {
        ret=true;
    }

    if(m_userManager->pagePosition(param))
    {
        ret=true;
    }
    return ret;
}

void QProjectWidget::make_page_position()
{
    tagPagePositionInfo info;
    info.m_data.insert("page_name",property("page_position"));
    QVariant v;
    v.setValue<tagPagePositionInfo>(info);
    m_propertyView->make_page_position(v);
    m_languageManager->make_page_position(v);
    m_userManager->make_page_position(v);


    m_propertyView->set_page_position(v);
    m_languageManager->set_page_position(v);
    m_userManager->set_page_position(v);
}
